package ls.vuecp.gui.component;

import java.awt.Color;
import java.awt.Font;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.RectangularShape;

import ls.vuecp.gui.Size;

import tufts.vue.Resource;
import tufts.vue.VueResources;

public class LWNode extends LWContainer 
{
	LWNode(String label, float x, float y, RectangularShape shape)
    {
        initNode();
        
        super.label = label; // make sure label initially set for debugging
        
        setFillColor(DEFAULT_NODE_FILL);
//        if (shape == null)
//            setShape(ls.vuecp.gui.shape.RoundRect2D.class);
//          //setShape(new RoundRectangle2D.Float(0,0, 10,10, 20,20));
//        else if (shape != null)
//            setShapeInstance(shape);
        
        setStrokeWidth(DEFAULT_NODE_STROKE_WIDTH);
        setStrokeColor(DEFAULT_NODE_STROKE_COLOR);
        
        setLocation(x, y);       
        this.width = NEEDS_DEFAULT;
        this.height = NEEDS_DEFAULT;
        
        setFont(DEFAULT_NODE_FONT);
        setLabel(label);       
        
    }
    
    public LWNode(String label) {
        this(label, 0, 0);
    }
    LWNode(String label, RectangularShape shape) {
        this(label, 0, 0, shape);
    }
    LWNode(String label, float x, float y) {
        this(label, x, y, null);
    }
    LWNode(String label, Resource resource)
    {
        this(label, 0, 0);
//        setResource(resource);
    }
    
    public float width;
    public float height;
    
    public static final Font  DEFAULT_NODE_FONT = VueResources.getFont("node.font");
    public static final Color DEFAULT_NODE_FILL = VueResources.getColor("node.fillColor");
    public static final int   DEFAULT_NODE_STROKE_WIDTH = VueResources.getInt("node.strokeWidth");
    public static final Color DEFAULT_NODE_STROKE_COLOR = VueResources.getColor("node.strokeColor");
    public static final Font  DEFAULT_TEXT_FONT = VueResources.getFont("text.font");
    
    public static final int MIN_SIZE = 10;
    public static final Size MinSize = new Size(MIN_SIZE, MIN_SIZE);
    public static final float NEEDS_DEFAULT = Float.MIN_VALUE;
    
    protected RectangularShape mShape;
    protected boolean isAutoSized = true; // compute size from label & children
    
    private transient float mBoxedLayoutChildY;

    private transient boolean isRectShape = true;

    private transient Line2D.Float mIconDivider = new Line2D.Float(); // vertical line between icon block & node label / children
    private transient Point2D.Float mLabelPos = new Point2D.Float(); // for use with irregular node shapes
    private transient Point2D.Float mChildPos = new Point2D.Float(); // for use with irregular node shapes

    private transient Size mMinSize;

    private transient boolean inLayout = false;
    private transient boolean isCenterLayout = false;// todo: get rid of this and use mChildPos, etc for boxed layout also

    private java.awt.Dimension textSize = null; // only for use with wrapped text

    
    private void initNode() {
//        enableProperty(KEY_Alignment);
    }
    @Override
    public void setLocation(float x, float y)
    {
        //System.out.println("setLocation " + this);
        super.setLocation(x, y);

        // Must lay-out children seperately from layout() -- if we
        // just call layout here we'll recurse when setting the
        // location of our children as they they try and notify us
        // back that we need to layout.
        
//        layoutChildren();
    }
    
    public Color        getFillColor()                  { return mFillColor.get(); }
    public void         setFillColor(Color c)           { mFillColor.set(c); }
    public String       getXMLfillColor()               { return mFillColor.asString(); }
    public void         setXMLfillColor(String xml)     { mFillColor.setFromString(xml); }

    public Color        getTextColor()                  { return mTextColor.get(); }
    public void         setTextColor(Color c)           { mTextColor.set(c); }
    public String       getXMLtextColor()               { return mTextColor.asString(); }
    public void         setXMLtextColor(String xml)     { mTextColor.setFromString(xml); }

    public Color        getStrokeColor()                { return mStrokeColor.get(); }
    public void         setStrokeColor(Color c)         { mStrokeColor.set(c); }
    public String       getXMLstrokeColor()             { return mStrokeColor.asString(); }
    public void         setXMLstrokeColor(String xml)   { mStrokeColor.setFromString(xml); }

    public Font         getFont()               { return mFont.get(); }
    public void         setFont(Font font)      { mFont.set(font); }
    public String       getXMLfont()            { return mFont.asString(); }
    public void         setXMLfont(String xml)  { mFont.setFromString(xml); }
    
    public float        getStrokeWidth()                { return mStrokeWidth.get(); }
    public void         setStrokeWidth(float w)         { mStrokeWidth.set(w); }
    
}
